<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2022/3/21
 * Time: 14:45
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

namespace app\admin\controller\weixin;

use app\common\controller\AdminController;
use app\common\lib\ArrClass;
use app\common\lib\Show;
use app\common\lib\Status;
use think\App;
use think\Exception;

/**
 * Class Config
 * @package app\admin\controller\weixin
 * @ControllerAnnotation(title="微信配置管理")
 */
class Config extends AdminController
{
    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\BuddhaArticle();

        $this->assign('getStatusList', $this->model->getStatusList());

    }
    public function uploadPem(){
        if (!$this->request->isPost()) {
            throw new Exception("请求类型错误", 400);
        }
        $file = $this->request->file();
        if (empty($file)) {
            return Show::json_show(Status::status_error, "请上传图片");
        }
        $key = array_keys($file);
        $arrType = ArrClass::uploadAttr();
        try {
            $objClass = ArrClass::initClass($key[0], $arrType, [], true);
            $res = $objClass->upload($this->request);
        }catch (\Exception $e){
            return Show::json_show(Status::status_error,$e->getMessage());
        }
        if($res){
            return Show::json_show(Status::status_normal,"上传成功",[
                "url"=>public_path()."/".$res
            ]);
        }else{
            return Show::json_show(Status::status_error,'上传失败！请重试');
        }
    }
}